package org.ykh.service.result;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import static org.ykh.service.result.SysCode.SUCCEED;

/**
 * @author ykh
 */
@Data
@Schema(name = "Result", description = "通用结果封装")
public class Result<T> {

    @Schema(description = "提示信息", example = "获取不到内容", accessMode = Schema.AccessMode.READ_ONLY)
    private String message;
    @Schema(description = "实际的数据内容", accessMode = Schema.AccessMode.READ_ONLY)
    private T data;
    @Schema(description = "系统提示码", example = "4000")
    private String sysCode;

    public Result(T data, String sysCode, String message) {
        this.message = message;
        this.data = data;
        this.sysCode = sysCode;
    }

    public Result(String sysCode, String message) {
        this.message = message;
        this.sysCode = sysCode;
    }

    public Result(T data) {
        this.data = data;
    }

    public Result(){}

    public static <T> Result<T> ok(T data){
        return new Result<>(data, SUCCEED.code, SUCCEED.description);
    }

    public static Result<?> ok(){
        return new Result<>(SUCCEED.code, SUCCEED.description);
    }

    public static Result<?> error(String code,String description){
        return new Result<>(code, description);
    }

}
